package com.fdb.efp.console.api.rest;

import com.fdb.basic.framework.core.constant.DataRuleType;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.core.log.LogManager;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.console.service.facade.SRoleDataRuleService;
import com.fdb.efp.console.service.facade.BizFlowTaskService;
import com.fdb.efp.console.service.vo.BizFlowTaskVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class BizFlowTaskController extends AbstractController  {
	
	@Autowired
	@Qualifier("bizFlowTaskService")
	private BizFlowTaskService bizFlowTaskService;
	
	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;
	
	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/biz/flow/tasks", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<BizFlowTaskVO>> queryBizFlowTaskAll(
			@RequestBody BizFlowTaskVO vo) {		
		
		LogManager.info(vo.getTaskId(), bizFlowTaskService, "queryAll");
		
		//List<BizFlowTaskVO> outputVo = this.executeQueryList("queryAll", bizFlowTaskService, new Object[]{vo});
		
		List<BizFlowTaskVO> outputVo = null;
				
		// 根据用户角色获取用户权限方案
		//Map<String,String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		//DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
		DataRuleType dataRuleType = DataRuleType.getDataRuleType("01");
		//setUserInfoToVO(vo);
		switch (dataRuleType) {
		case Owner:
			outputVo = bizFlowTaskService.queryAllOwner(vo);
			break;
		case CurrOrg:
			outputVo = bizFlowTaskService.queryAllCurrOrg(vo);
			break;
		case CurrDownOrg:
			outputVo = bizFlowTaskService.queryAllCurrDownOrg(vo);
			break;
		default:
			outputVo = bizFlowTaskService.queryAllOwner(vo);
			break;
		}
		
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/biz/flow/task/{taskId}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<BizFlowTaskVO> queryByPk(@PathVariable("taskId") String taskId) {		
		BizFlowTaskVO inVo = new BizFlowTaskVO();
				inVo.setTaskId(taskId);
		BizFlowTaskVO outputVo = bizFlowTaskService.queryByPk(inVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键删除信息
	 * @param bizFlowTask
	 * @return
	 */
	@RequestMapping(value="/biz/flow/task", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody BizFlowTaskVO inBizFlowTaskVo) {		
		int outputVo = bizFlowTaskService.deleteByPk(inBizFlowTaskVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键更新信息
	 * @param inBizFlowTaskVo
	 * @return
	 */
	@RequestMapping(value="/biz/flow/task", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody BizFlowTaskVO inBizFlowTaskVo) {		
		int outputVo = bizFlowTaskService.updateByPk(inBizFlowTaskVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 新增数据
	 * @param inBizFlowTaskVo
	 * @return
	 */
	@RequestMapping(value="/biz/flow/task", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertBizFlowTask(@RequestBody BizFlowTaskVO inBizFlowTaskVo) {
		int outputVo = bizFlowTaskService.insertBizFlowTask(inBizFlowTaskVo);
		return getResponseData(outputVo);
	}
	
	/**
	 * 可选前置任务数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/biz/flow/pertasks", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<BizFlowTaskVO>> queryEnableSelectPreTask(
			@RequestBody BizFlowTaskVO vo) {		
		List<BizFlowTaskVO> outputVo = bizFlowTaskService.queryEnableSelectPreTaskByPage(vo);
		return getResponseData(outputVo);
	}
}
